package com.eam.asset.assetApplication.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.eam.asset.assetApplication.vo.AssetApplicationAddVo;
import com.eam.asset.assetApplication.vo.AssetApplicationPutVo;
import com.eam.asset.assetApplication.vo.AssetApplicationQueryVo;
import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.eam.common.annotation.Log;
import com.eam.common.core.controller.BaseController;
import com.eam.common.core.domain.AjaxResult;
import com.eam.common.enums.BusinessType;
import com.eam.asset.assetApplication.domain.AssetApplication;
import com.eam.asset.assetApplication.service.IAssetApplicationService;
import com.eam.common.utils.poi.ExcelUtil;
import com.eam.common.core.page.TableDataInfo;

/**
 * 资产处置申请Controller
 *
 * @author tzf
 * @date 2023-10-31
 */
@RestController
@RequestMapping("/asset/assetApplication")
@Validated
@Api(tags = "资产处置申请控制器")
public class AssetApplicationController extends BaseController {
    private final IAssetApplicationService assetApplicationService;

    @Autowired
    public AssetApplicationController(IAssetApplicationService assetApplicationService) {
        this.assetApplicationService = assetApplicationService;
    }

    /**
     * 查询资产处置申请列表
     */
    @PreAuthorize("@ss.hasPermi('asset:assetApplication:list')")
    @GetMapping("/list")
    public TableDataInfo list(AssetApplicationQueryVo assetApplication) {
        startPage();
        List<AssetApplication> list = assetApplicationService.selectAssetApplicationList(assetApplication);
        return getDataTable(list);
    }

    /**
     * 导出资产处置申请列表
     */
    @PreAuthorize("@ss.hasPermi('asset:assetApplication:export')")
    @Log(title = "资产处置申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssetApplicationQueryVo assetApplication) {
        List<AssetApplication> list = assetApplicationService.selectAssetApplicationList(assetApplication);
        ExcelUtil<AssetApplication> util = new ExcelUtil<AssetApplication>(AssetApplication.class);
        util.exportExcel(response, list, "资产处置申请数据");
    }

    /**
     * 获取资产处置申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('asset:assetApplication:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(assetApplicationService.selectAssetApplicationById(id));
    }

    /**
     * 新增资产处置申请
     */
    @PreAuthorize("@ss.hasPermi('asset:assetApplication:add')")
    @Log(title = "资产处置申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssetApplicationAddVo assetApplication) {
        return toAjax(assetApplicationService.insertAssetApplication(assetApplication));
    }

    /**
     * 修改资产处置申请
     */
    @PreAuthorize("@ss.hasPermi('asset:assetApplication:edit')")
    @Log(title = "资产处置申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody AssetApplicationPutVo assetApplication) {
        return toAjax(assetApplicationService.updateAssetApplication(assetApplication));
    }

    /**
     * 删除资产处置申请
     */
    @PreAuthorize("@ss.hasPermi('asset:assetApplication:remove')")
    @Log(title = "资产处置申请", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(assetApplicationService.deleteAssetApplicationByIds(ids));
    }
}
